<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/views/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/views/include/nocachehead.jsp"%>
<title>${requestScope.album.ownerNickname}的相册</title>
</head>
<body>
	<div>
		<!-- main content start -->
		<div>
			<c:if test="${requestScope.message ne ''}">
				<c:out value="${requestScope.message}" escapeXml="false"/>
			</c:if>
		</div>
		<div>
			<c:if test="${requestScope.album.cover eq 'cover_s'}">
				<c:set var="needCover" value="1" scope="page" />
			</c:if>
			<c:out value="${requestScope.errMsg}" escapeXml="false"/>
			<form id="editPhotoForm" method="POST" action="${pageContext.request.contextPath}/album/uploadok/${requestScope.album.id }.html">
				<skyline:setSessionAttrToVar var="SESSION_UPLOAD_OK_FILES" key="SESSION_UPLOAD_OK_FILES"/>
				<c:forEach items="${pageScope.SESSION_UPLOAD_OK_FILES[requestScope.album.id]}" var="photo" varStatus="status">
					<p>
						<img src="${pageContext.request.contextPath}/image/${photo.smallFile}.${photo.ext}">
						<label>描述:</label>
						<textarea name="description" id="desc_${photo.id }" rows="" cols=""></textarea>
						<input type="hidden" name="id" value="${photo.id}"/>
						<span id="description_tip"></span>
						<input type="radio" id="cover_${photo.id }" name="cover" value="${photo.smallFile}" 
							<c:if test="${status.index eq 0 and needCover eq '1'}">
								checked="checked"
							</c:if> /> <label for="cover_${photo.id }">设为封面</label>
					</p>
					<input type="radio" name="ext" id="ext_${photo.id }" value="${photo.ext}" style="display: none;"
						<c:if test="${status.index eq 0 and needCover eq '1'}">
							checked="checked"
						</c:if> />
				</c:forEach>
				<input type="hidden" name="submitToken" value="<skyline:sessionAttribute key="SESSION_SUBMIT_TOKEN" />">
				<c:if test="${fn:length(pageScope.SESSION_UPLOAD_OK_FILES[requestScope.album.id])>0}">
					<input type="submit" value="修改" class="" />
				</c:if>
				<input type="button" value="取消" class="" onclick="window.location='${pageContext.request.contextPath}/album/view/${requestScope.album.id}.html';"/>
			</form>
			<script type="text/javascript">
			(function($){
				$('input[name=cover]').each(function(){
					$(this).click(function(){
						var id = this.id;
						var photoId = id.substring(id.indexOf('_')+1);
						$('#ext_'+photoId).attr('checked',true);
					});
				});
				$('textarea[name=description]').each(function(){
					$(this).keyup(function(){
						var msg = "描述信息不能多于200个字";
						var id=this.id;
						var idno=id.substring(id.indexOf('_')+1);
						if(this.value.length>200){
							$(this).addClass("error");
							if(!$('#err_'+idno)[0]) {
								$(this).after('<label for="desc_'+idno+'" id="err_'+idno+'" class="error">'+msg+'</label>');
							}
						} else {
							$(this).removeClass("error");
							if($('#err_'+idno)[0]) {
								$('#err_'+idno).remove();
							}
						}
						
					}).blur(function(){
						$(this).keyup();
					});
				});
				$('#editPhotoForm').unbind('submit').submit(function(){
					var valid = true;
					$('textarea[name=description]').each(function(){
						if(this.value.length>200){$(this).focus();valid = false;}
					});
					return valid;
				});
			})($);
			</script>
		</div>
		<!-- main content end -->
	</div>
</body>
</html>